<?php

/**
 * @encoding     :   UTF-8
 * @author      :   2013-1-21 16:52:40 by Lsl8966 , 470663151@qq.com , http://www.cnblogs.com/lsl8966
 * @Package     :
 * @version   
 */

function SortByOrderIdAsc($a,$b){
    if(is_array($a) && is_array($b)){
        $a_dt = $a["order_id"];
        $b_dt = $b["order_id"];
        if($a_dt == $b_dt){
            return 0;
        }
        return ($a_dt<$b_dt)?-1:1;
    }
}


function SortByOrderIdDesc($a,$b){
    if(is_array($a) && is_array($b)){
        $a_dt = $a["create_time"];
        $b_dt = $b["create_time"];
        if($a_dt == $b_dt){
            return 0;
        }
        return ($a_dt>$b_dt)?-1:1;
    }
}

function getTimestamp(){
    return time().  substr(microtime(), 2,6);
}

function g2kilogramNew($num,$spec_id){
    if($spec_id == 0){
        return $num/500;
    } else {
        return $num;
    }
}

/**
 * 找出当前条目下所有的子条目
 *@Param int $pid 父ID
 *@Param Array
 **/
function getArrayCidByParentid($model, $catid,$p_field = 'parent_id',$c_field = 'kind_id', &$target){
    $map[$p_field] = $catid;
    $cid = $model->where($map)->select();
    /* 将匹配的查找到的添加到数组中 */
    foreach( $cid as $k => $v ) {
        array_push( $target, $v[$c_field]);
        if( !empty( $cid[$k][$p_field]) ) {
            getArrayCidByParentid($model, $v[$c_field],$p_field ,$c_field,$target );
        }
    }
    return $target;
}
function getProductSalePriceByUserType($type,$vo,$is_hot_slae=1){
	if($is_hot_slae == 1){
		$promtion_model = Controller::createMode('db_sys_26_71','t_26_product_promotion');
		$goods = $promtion_model->getOne("m_deliver_limit_time > '".date("Y-m-d H:i:s")."' and state=1 and item_no=".$vo['item_no']);
		if($goods && $goods['price'] > 0){
			return round($goods['price'],2);
		}
	}
	$price = $vo['scheme_price'];//默认配送价格
	switch($type){
		case 1://进价
			$price = $vo['price'];break;
		case 3://配送价
			$price = $vo['scheme_price'];break;
		case 7://批发
			$price = $vo['base_price'];break;
		case 8://批发1
			$price = $vo['base_price1'];break;
		case 9://批发2
			$price = $vo['base_price2'];break;
		case 10://批发3
			$price = $vo['base_price3'];break;
		case 11://批发4
			$price = $vo['base_price4'];break;
	}
	return round($price,2);
}
//退货标志
function getProductRefundTitle($vo){
	$title_configs = config('pro_code1');
	return strip_tags ($title_configs[$vo['pro_code2']])	;
}

function getProductRefundTitleEx($pro_code2){
	$title_configs = config('pro_code1');
	return $title_configs[$pro_code2]	;
}